﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PrimeAlgos;

namespace PrimeAlgos
{
    public class SievePrimer
    {
        public int EndPoint { get; private set; }


        public SievePrimer(int endPoint)
        {
            EndPoint = endPoint;

            if (endPoint <= 2)
                throw new Exception("EndPont <= 2, choose interger value higher than 2...");
        }

        
        public SieveNumber[] GetPrimesUsingSieveOfEratosthenes()
        {
            //http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

            int p = 2;
            SieveNumber[] primes = new SieveNumber[EndPoint];

            //Start crossing out values start from p=2
            for (int i = p; i < 10; i++)
            {
                for (int j = i; j < EndPoint; j += i)
                {
                    if (j > i)
                        primes[j].IsCrossed = true;
                }
            }

            return primes.Where(pr => pr.Value > 1 && pr.IsCrossed == false).ToArray();
        }

    }
}
